#pragma once
#include <QByteArray>
#include <QList>

struct User {
    quint16 id;
    QByteArray username;
    quint16 userType; // 0: 工业人员    1: 专家

    User() : id(0), username("null"), userType(0) {}

    User(const quint16& id, const QByteArray& username, const quint16& userType) 
        : id(id), username(username), userType(userType) {}

    const QByteArray toByteArray() const {
        return QByteArray::number(id) + ',' + username + ',' + QByteArray::number(userType);
    }

    static User read(const QByteArray& data) {
        QList<QByteArray> parts = data.split(',');
        if (parts.size() != 3) {
            throw std::invalid_argument("Invalid User data format");
        }
        return User(parts[0].toUShort(), parts[1], parts[2].toUShort());
    }
};